﻿using ConfExpert.Forms.Base;
using DevExpress.XtraEditors.Repository;
using DevTeam;

using System;
using System.Windows.Forms;

namespace ConfExpert.Forms.Depo
{
    public partial class TelaCikislari : XForm
    {
        public TelaCikislari()
        {
            InitializeComponent();
        }

        BindingSource bs;
        private void TelaCikislari_Load(object sender, EventArgs e)
        {
            
            splitContainerControl2.AutoSize();
            ((RepositoryItemComboBox)cmb.Edit).TextEditStyle = DevExpress.XtraEditors.Controls.TextEditStyles.DisableTextEditor;
            ((RepositoryItemComboBox)cmb.Edit).SelectedIndexChanged += cmb_SelectedIndexChanged;
           // cmb.SelectedIndex = 0;
        }

        void cmb_SelectedIndexChanged(object sender, EventArgs e)
        {
           
            switch (cmb.EditValue.ToString())
            {
                case "Customer":
                    bs = gv1.Init("GetTelaCikis2", 0);
                    gv1.AddDetailGrid(gv2, "CustomerId");
                    gv2.MakeColumnInvisible("CustomerId");
                    gv2.FormatAsDate("Tarih");
                    break;

                case "Tela artikeli":
                    bs = gv1.Init("GetTelaCikis2", 1);
                    gv1.AddDetailGrid(gv2, "TelaId");
                    gv2.MakeColumnInvisible("TelaId");
                    gv2.FormatAsDate("Tarih");
                    break;

                case "Atölye":
                    bs = gv1.Init("GetTelaCikis2", 2);
                    gv1.AddDetailGrid(gv2, "CikisYeriId");
                    gv2.MakeColumnInvisible("CikisYeriId");
                    gv2.FormatAsDate("Tarih");
                    break;

                case "Tarih":
                    bs = gv1.Init("GetTelaCikis2", 3);
                    gv1.AddDetailGrid(gv2, "Tarih");
                    gv2.MakeColumnInvisible("Tarih");
                    gv1.FormatAsDate("Tarih");
                    break;

                case "Üreticiye iade":
                    bs = gv1.Init("GetTelaCikis2", 4);
                    gv1.AddDetailGrid(gv2, "CikilanUreticiId");
                    gv2.MakeColumnInvisible("CikilanUreticiId");
                    gv1.Columns["CikilanUreticiId"].ColumnEdit = RI(Rp.Vendor);
                    break;

            }

            bs.CurrentChanged -= bs_CurrentChanged;
            bs.CurrentChanged += bs_CurrentChanged;

            gv1.MakeReadOnly();
            gv2.MakeReadOnly();
            gv2.Columns["CikilanUreticiId"].ColumnEdit = RI(Rp.Vendor);
            gv1.FormatAsNumber(0, "ToplamCikan");
            gv2.FormatAsNumber(0, "CikanMiktar");
            gv1.AddSummary("ToplamCikan");
            gv2.AddSummary("CikanMiktar");
            gv1.BestFitColumns();
            gv2.BestFitColumns();

        }

        void bs_CurrentChanged(object sender, EventArgs e)
        {
            gv2.BestFitColumns();
        }
    }
}
